/*
 * Galaxium Messenger
 * 
 * Copyright (C) 2008 Philippe Durand <draekz@gmail.com>
 * 
 * License: GNU General Public License (GPL)
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.IO;

namespace Galaxium.Protocol.GaduGadu
{
	public class SetStatusCommand : GaduCommand
    {
        private int _status;
        private byte[] _description;
        
        public int Status
        {
            get{return _status; }
            set { _status = value; }
        }
        
        public string Description
        {
            get
            {
                Encoding enc = Encoding.Unicode;
                return enc.GetString (Encoding.Convert (Encoding.GetEncoding ("windows-1250"), Encoding.UTF8, _description));
            }
            set
            {
                _description = new byte[value.Length + 1];
                Encoding enc = Encoding.GetEncoding("windows-1250");
                byte[] cp1250;
                cp1250 = enc.GetBytes(value);
                for (int i = 0; i < value.Length; i++)
                    _description[i] = cp1250[i];
                _description[value.Length]=(byte)'\0';
            }
        }
        
        public SetStatusCommand (int status, string description) : base (GaduConstants.CMD_OUT_NEW_STATUS)
        {
        	_status = status;
        	Description = description;
        }
        
        protected override void Write (BinaryWriter writer)
        {
            writer.Write (_status);
            
            for (int i = 0; i < _description.Length; i++)
                writer.Write (_description[i]);
        }
        
        public override string ToString ()
        {
        	return String.Empty;
        }
    }
}